package com.guigu.oss.controller;

import com.guigu.common.utils.R;
import com.guigu.oss.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/oss/fileoss")
public class OssController {

    @Autowired
    private OssService ossService;

    //上传文件
    @PostMapping("/uploadAvatarToOss")
    public R uploadAvatarToOss(MultipartFile file){
        String url = ossService.uploadFileAvatar(file);
        if(url==null){
            throw new RuntimeException("上传图片失败");
        }
        return R.ok().data("url", url);
    }

    //上传设备图片
    @PostMapping("/uploadEquipmentImage")
    public R uploadEquipmentImage(MultipartFile file){
        String url = ossService.uploadEquipmentImage(file);
        if(url==null){
            throw new RuntimeException("上传图片失败");
        }
        return R.ok().data("url", url);
    }
}
